package com.weapons.week0903_weapons;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;


import com.weapons.week0903_weapons.adapter.VpAdapter;
import com.weapons.week0903_weapons.fragment.ForumFragment;
import com.weapons.week0903_weapons.fragment.ImageFragment;
import com.weapons.week0903_weapons.fragment.RecommendFragment;
import com.weapons.week0903_weapons.fragment.RoundFragment;
import com.weapons.week0903_weapons.fragment.WeaponsFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

public class MainActivity extends AppCompatActivity {


    @InjectView(R.id.vp_content)
    ViewPager mVpContent;
    @InjectView(R.id.tl_bottom)
    TabLayout mTlBottom;
    private String[] mTitles = {"推荐", "环球", "图片", "论坛", "武器"};
    private int[] mIcons = {R.drawable.recommend, R.drawable.round, R.drawable.image,R.drawable.forum, R.drawable.weapons};
    private List<Fragment> mFragment;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.inject(this);
        mFragment = new ArrayList<>();
        initFragment();
        mVpContent.setAdapter(new VpAdapter(getSupportFragmentManager(),this,mFragment));
        mTlBottom.setupWithViewPager(mVpContent);//tablayout和viewpager联动起来
        int tabCount = mTlBottom.getTabCount();
        //动态设置标题和图片
        for (int i = 0; i < tabCount; i++) {
            TabLayout.Tab tab = mTlBottom.getTabAt(i);
            tab.setText(mTitles[i]).setIcon(mIcons[i]);//改变底部标题的显示和图片的显示
        }

    }


    private void initFragment() {
        mFragment.add(new RecommendFragment().newInstance("pos"));
        mFragment.add(new RoundFragment().newInstance("pos"));
        mFragment.add(new ImageFragment().newInstance("pos"));
        mFragment.add(new ForumFragment().newInstance("pos"));
        mFragment.add(new WeaponsFragment().newInstance("pos"));
    }

}
